//
//  JCCartoonViewController.m
//  ABookOfCartoon
//
//  Created by dlios on 15-5-18.
//  Copyright (c) 2015年 Power Of Ants. All rights reserved.
//

#import "JCCartoonViewController.h"
#import "JCReadModel.h"
#import "UIImageView+WebCache.h"

@interface JCCartoonViewController ()<UIScrollViewDelegate>

@property(nonatomic,retain)NSMutableArray *dataArr;
@property(nonatomic,retain)NSMutableArray *arr1;
@property(nonatomic,retain)UIScrollView *scrollView;

@end

@implementation JCCartoonViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.tabBarController.tabBar.hidden = NO;
    self.navigationController.navigationBar.translucent = NO;
    self.tabBarController.tabBar.translucent = NO;
    
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 46)];
    _scrollView.pagingEnabled = YES;
    _scrollView.bounces = NO;
    
    _scrollView.delegate = self;

//    _scrollView.backgroundColor = [UIColor redColor];

    [self.view addSubview:_scrollView];
//    NSLog(@"~~~~~~~~~~~~%ld",self.arr1 objectAtIndex:);
    [self getDataFromWeb1];
    
}
-(void)creatImage
{
    for (int i = 0; i < self.arr1.count; i++) {
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width * i, 0, self.view.frame.size.width, self.view.frame.size.height)];

//        image.backgroundColor = [UIColor grayColor];
//        [image sd_setImageWithURL:[NSURL URLWithString:[self.arr1 objectAtIndex:i]]placeholderImage:[UIImage imageNamed:@"/Users/dlios/ABookOfCartoon/ABookOfCartoon/9.jpg"]];
//        image sd_setImageWithURL:[NSURL URLWithString:[self.arr1 objectAtIndex:i]] placeholderImage:<#(UIImage *)#>];
        [image sd_setImageWithURL:[NSURL URLWithString:[self.arr1 objectAtIndex:i]]placeholderImage:[UIImage imageNamed:@"10.jpg"]];
        [_scrollView addSubview:image];
    }
    
}
-(void)getDataFromWeb1
{
    NSString *strEncoding = [_str9 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:strEncoding];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        NSMutableArray *arr = result;
        self.dataArr = [NSMutableArray array];
        self.arr1 = [NSMutableArray array];
        for (NSMutableDictionary *dic in arr) {
            JCReadModel *m = [[JCReadModel alloc]initWithDic:dic];
            [self.arr1 addObject: [dic objectForKey:@"PictureURL"]];
            [_dataArr addObject:m];
            [m release];
        }
        _scrollView.contentSize = CGSizeMake((self.view.frame.size.width)  * self.arr1.count, self.view.frame.size.height);
        [self creatImage];
        
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
